public class YesterDate {

    public static String getYesterday(int year, int month, int day) {
        if (year < 1900 || year > 2050) {
            throw new IllegalArgumentException("年份必须在1900-2050之间");
        }
        if (month < 1 || month > 12) {
            throw new IllegalArgumentException("月份必须在1-12之间");
        }
        int maxDays = getMaxDays(year, month);
        if (day < 1 || day > maxDays) {
            throw new IllegalArgumentException("日期无效");
        }

        // 计算前一天
        if (day > 1) {
            day--;
        } else {
            if (month == 1) {
                year--;
                month = 12;
                day = 31;
            } else {
                month--;
                day = getMaxDays(year, month);
            }
        }

        return String.format("%d-%d-%d", year, month, day);
    }

    private static int getMaxDays(int year, int month) {
        switch (month) {
            case 1: case 3: case 5: case 7: case 8: case 10: case 12:
                return 31;
            case 4: case 6: case 9: case 11:
                return 30;
            case 2:
                return isLeapYear(year) ? 29 : 28;
            default:
                throw new AssertionError("无效的月份");
        }
    }

    private static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
}